<?php
elgg_load_library('elgg:class_organization');

$org 		= get_entity(get_input('o'));
$username 	= get_input('admin','');

//Security check
if(!$org->isManager()) forward();

//Get the user entity with the username
$query = "SELECT guid FROM ".$CONFIG->dbprefix."users_entity WHERE username = '".$username."'";
$result = get_data_row($query);

if(is_object($result))
{
	$user = get_entity($result->guid);
}
else
{
	forward(REFERER);
}

if($org->addManager($user->guid))
{
	system_message("Se agrego a ".$user->username." como administrador");
}
else
{
	register_error("Error: No se pudo agregar al administrador");
}

forward(REFERER);
?>